﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Db4objects.Db4o.Linq;
using Hover.Common.Repositories;

namespace Hover.Repository.DB4O.Provider.Repositories
{
    public class Repository<T> : IRepository<T>
    {
        #region IRepository<T> Members

        public IQueryable<T> GetAll()
        {
            return (from T items in DB4OHelper.Container
                    select items).AsQueryable();
        }

        public IPagedList<T> GetPaged(int pageIndex, int pageSize)
        {
            var query = (from T items in DB4OHelper.Container
                         select items).AsQueryable();
            return new PagedList<T>(query, pageIndex, pageSize); 
        }

        public IQueryable<T> Find(System.Linq.Expressions.Expression<Func<T, bool>> expression)
        {
            return GetAll()
                .Where(expression);
        }

        public void Save(T item)
        {
            DB4OHelper.Container.Store(item);
        }

        public void Delete(T item)
        {
            DB4OHelper.Container.Delete(item);
        }

        #endregion

    }
}
